package com.example.no1admin.controller;

import com.example.no1admin.pojo.vo.user.UserListVO;
import com.example.no1admin.pojo.dto.user.UserUpdateDTO;
import com.example.no1admin.service.IUserService;
import com.example.no1admin.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "用户管理模块")
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    private IUserService userService;

    @PreAuthorize("hasAuthority('/ams/admin/read')")
    @GetMapping("")
    @ApiOperation("用户列表")
    @ApiOperationSupport(order = 300)
    public JsonResult list(){
        log.debug("控制器开始执行查询用户列表！");
        List<UserListVO> list = userService.list();
        log.debug("控制器查询到的用户列表数据:{}",list);
        return JsonResult.ok(list);
    }

    @PreAuthorize("hasAuthority('/ams/admin/update')")
    @PostMapping("/update-enable-by-id")
    @ApiOperation("修改用户状态")
    @ApiOperationSupport(order = 400)
    public JsonResult updateEnable(@RequestBody UserUpdateDTO userUpdateDTO){
        log.debug("控制器开始处理用户状态更改!");
        userService.updateById(userUpdateDTO);
        return JsonResult.ok();
    }

}
